package net.googlecode.kharchenko.controllers;

import net.googlecode.kharchenko.services.PersonService;
import net.googlecode.kharchenko.services.SecurityService;
import net.googlecode.kharchenko.domains.Person;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;


import java.io.IOException;

/**
 * Controller of main user page.
 */
@Controller
public class HomeController {

    @Autowired
    private PersonService personService;
    @Autowired
    private SecurityService securityService;

    protected static final Logger logger = Logger.getLogger(IndexController.class);

    /**
     * Return home page.
     *
     * @return home page
     */
    @RequestMapping("/home")
    public ModelAndView handleRequest() {
        ModelAndView mv = new ModelAndView("home");
        logger.info("Get current person");
        Person prs = personService.getPerson(securityService.getCurrentUser());
        mv.addObject("groupmates", personService.getGroupMates(prs));
        mv.addObject("info", prs);
        mv.addObject("top5", personService.getTop5());
        logger.info("Returning user page view");
        return mv;
    }

}